home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9760 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: apccorp.apcc.com!root
  2. From: nfegan@apcc.com (Noel Fegan)
  3. Newsgroups: gnu.g++.help,comp.lang.c++
  4. Subject: Re: IS THIS LEGAL? Static method returns pointer to class
  5. Date: Mon, 04 Mar 1996 11:10:21 GMT
  6. Organization: American Power Conversion
  7. Message-ID: <4hej4b$ou1@apccorp.apcc.com>
  8. References: <4hdu70$efa@panix.com>
  9. NNTP-Posting-Host: hewie.galway.apcc.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. acinader@panix.com (Arthur Cinader Jr) wrote:
  13.  
  14. >I may be going at this wrong, but I want to have a class
  15. >Triangle contain a static method called makeinstance.  The
  16. >method will be passed a refernce to a Param object that has
  17. >a list of parameters for checking first and then passing to 
  18. >the Triangle constructor.
  19.  
  20. >The parameters are checked and if all is ok, a Triangle
  21. >instance is "newed" and the pointer to the new Trinagle is
  22. >returned.  When I compile, I get the following error:
  23.  
  24. >% g++ -c triangle.C
  25. >In file included from triangle.C:8:
  26. >triangle.h:17: syntax error before `*'
  27. >...
  28. >%
  29.  
  30. >***The declaration for the class:
  31.  
  32. >      1 // triangle.h
  33. >      2 // declaration of class Triangle extends shape
  34. >      3
  35. >      4 #ifndef TRIANGLE_H
  36. >      5 #define TRIANGLE_H
  37. >      6
  38. >      7 #include "point.h"
  39. >      8 #include "param.h"
  40. >      9
  41. >     10 class Trianlge : public Point {
  42. >     11 public:
  43. >     12     Trinagle(float = 0.0, float = 0.0, float = 0.0);
  44. >     13     float gets() const;
  45. >     14     virtual void draw() const;
  46. >     15
  47. >     16     static Param &getParams();
  48. >     17     static Triangle *makeinstance(Param &);
  49. >     18 private:
  50. >     19     float side;
  51. >     20 };
  52. >     21
  53. >     22 #endif
  54.  
  55. The idea looks fine to me. However, if this is a direct copy of the code you
  56. wrote you better mind your spelling. The word Triangle is spelled differently in
  57. the three place it appears:
  58.  
  59. class Trianlge...
  60.  
  61. Trinagle(float....
  62.  
  63. static Triangle *makeinstance...
  64.  
  65. This would definitely cause the problem you described...
  66.  
  67. --
  68. Noel Fegan
  69. European Software Development Department
  70. American Power Conversion
  71. My views used to be my own, and then I got married...
  72. I don't speak for APC...
  73. nfegan@apcc.com
  74.  
  75.